package com.taoyibao.hongcanting.ui.login.delegate;

import android.content.Intent;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;

import com.taoyibao.hongcanting.R;
import com.taoyibao.hongcanting.base.delegate.BackToolbarDelegate;
import com.taoyibao.hongcanting.ui.login.activity.LoginActivity;
import com.taoyibao.hongcanting.ui.login.activity.SetLoginPwdActivity;
import com.taoyibao.hongcanting.utils.CodeUtils;
import com.taoyibao.hongcanting.utils.ToastUtils;

/**
 * @author TangAnna
 * @description: 注册
 * @date :${DATA} 17:49
 */
public class RegisterDelegate extends BackToolbarDelegate implements View.OnClickListener {
    @Override
    public int getRootLayoutId() {
        return R.layout.activity_register;
    }

    @Override
    public void initWidget() {
        super.initWidget();
        setTitle("注册");
        get(R.id.tv_register_login).setOnClickListener(this);
        get(R.id.tv_register_next).setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.tv_register_login://去登录
                LoginActivity.open(getActivity(), "RegisterDelegate");
                break;
            case R.id.tv_register_next://下一步
                getActivity().startActivity(new Intent(getActivity(), SetLoginPwdActivity.class));
                break;
        }
    }

    /**
     * 判断是否可以获取验证码
     *
     * @return
     */
    public boolean isCanVCode() {
        if (TextUtils.isEmpty(getPhone())) {
            //提示输入手机号
            ToastUtils.showToast(CodeUtils.getIdString(R.string.string_hintEmptyPhone));
            return false;
        } else if (!CodeUtils.judgePhoneNumber(getPhone())) {
            //手机号不合法
            ToastUtils.showToast(getActivity().getResources().getString(R.string.string_hintPhoneError));
            return false;
        }
        return true;
    }

    /**
     * 判断下一步是否可操作
     *
     * @return
     */
    public boolean isCanNext() {
        if (!TextUtils.isEmpty(getPhone()) && !TextUtils.isEmpty(getVCodeStr())) {
            return true;
        }
        return false;
    }

    /**
     * 获取手机号
     *
     * @return
     */
    public String getPhone() {
        return ((EditText) get(R.id.et_register_phone)).getText().toString();
    }

    /**
     * 获取验证码
     *
     * @return
     */
    public String getVCodeStr() {
        return ((EditText) get(R.id.et_register_vcode)).getText().toString();
    }


}
